<?php
RegisterPlugin("plain","ActivePlugin_plain");
function ActivePlugin_plain(){
	Add_Filter_Plugin('Filter_Plugin_Admin_TopMenu','plain_AddMenu');
	Add_Filter_Plugin('Filter_Plugin_Zbp_MakeTemplatetags','plain_Footer');
}

function plain_AddMenu(&$m){
	global $zbp;
	array_unshift($m, MakeTopMenu("root",'主题配置',$zbp->host . "zb_users/theme/plain/main.php?act=config","","topmenu_plain"));
}
function plain_SubMenu($id){
	$arySubMenu = array(
		0 => array('基本设置', 'config', 'left', false),
		1 => array('其它设置', 'other', 'left', false),
	);
	foreach($arySubMenu as $k => $v){
		echo '<a href="?act='.$v[1].'" '.($v[3]==true?'target="_blank"':'').'><span class="m-'.$v[2].' '.($id==$v[1]?'m-now':'').'">'.$v[0].'</span></a>';
	}
}
function plain_Footer(&$template) {
    global $zbp;
    $zbp->footer .= '<div id="theme"><p>Theme By <a href="https://www.boke8.net" title="博客吧" target="_blank">博客吧</a>.</p></div>'."\r\n";
}
function InstallPlugin_plain(){
	global $zbp;
    if(!$zbp->Config('plain')->HasKey('Version')){
		$zbp->Config('plain')->Version = '1.0';
		/*seo设置*/
		$zbp->Config('plain')->seo = '1';	
		$zbp->Config('plain')->title = '';
		$zbp->Config('plain')->keywords = '';
        $zbp->Config('plain')->description = '';
		$zbp->Config('plain')->separator = '_';
		$zbp->Config('plain')->tongji = '';	
		/*ad*/
		$zbp->Config('plain')->topad = '';
		$zbp->Config('plain')->topadNO = 0;
		$zbp->Config('plain')->btmad = '';
		$zbp->Config('plain')->btmadNO = 0;
		$zbp->Config('plain')->postad = '';
		$zbp->Config('plain')->postadNO = 0;
	}
		$zbp->SaveConfig('plain');
}
function UninstallPlugin_plain(){
	global $zbp;
}
function plain_thumbnail($related) {
    global $zbp;	
	$pattern="/<[img|IMG].+?src=[\'|\"](.+?)[\'|\"].+?[\/]?>/";
	$content = $related->Content; 
	preg_match_all($pattern,$content,$matchContent);
	if(isset($matchContent[1][0])){
		$thumb=$matchContent[1][0]; 
	}else{		
		$thumb=$zbp->host .'zb_users/theme/plain/style/images/no-image.jpg';	
	}
    return $thumb;
}
function plain_intro($as,$type,$long,$other){
	global $zbp;
    $str = '';
     if ($type=='0') {
    $str .= trim(htmlentities(SubStrUTF8(TransferHTML($as->Intro,'[nohtml]'),$long), ENT_COMPAT, 'UTF-8')).$other;
    } else {
    $str .= trim(htmlentities(SubStrUTF8(TransferHTML($as->Content,'[nohtml]'),$long), ENT_COMPAT, 'UTF-8')).$other;
    }
    return $str;
}
?>